﻿@using Telerik.Web.Mvc.UI
@model IEnumerable< EcBlog.Admin.Models.ServerFile> 
@{
    ViewBag.Title = "Manage Files";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
} 
@using (Html.BeginForm("Delete", "FileBrowser", FormMethod.Post))
{
    var checkedNodes = ViewData["FileBrowser_checkedNodes"] as List<TreeViewItem>;
    @(Html.Telerik().TreeView()
            .Name("FileBrowser")
            .ShowCheckBox(true)
            .HtmlAttributes(new { @class = "t-group" })
            .ClientEvents(events => events 
                    .OnSelect("onNodeSelect")
                    .OnNodeDrop("onNodeDrop"))
            .BindTo(Model, (item, serverFile) =>
            {
                item.Text = serverFile.Name;
                item.Value = serverFile.FullPath;
                item.LoadOnDemand = serverFile.IsDirectory;
            })
            .DataBinding(dataBinding => dataBinding
                    .Ajax().Select("AjaxLoading", "FileBrowser")
            )
    )
    
     <p>
        <button type="submit" class="t-button t-state-default">Delete</button>

    </p>
    
if (checkedNodes != null && checkedNodes.Count > 0)
{
        <p>
            <strong>You have deleted the following items:</strong><br />
            <span>@Html.Raw(ViewData["message"].ToString())</span>
        </p>
}
}
@using (Html.BeginForm("Edit", "FileBrowser",FormMethod.Get))
{   
    <p>
        <input type="hidden" id="selectedPath" name="selectedPath" />
        <button type="submit" class="t-button t-state-default">Edit</button>
    </p>
}

@using (Html.BeginForm("ProcessSubmit", "FileBrowser",
                         FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data", }))
{ 
    @(Html.Telerik().Upload()
            .Name("attachments")
    )
    <input type="hidden" id="selectedPath" name="selectedPath" />

    <p class="note">
        Maximum combined file size: 10 MB
    </p>
    <div style="margin: 20px 0 0 0;">
        <input type="submit" value="Send" class="t-button" />
        <input type="reset" value="Reset" class="t-button" />
    </div>
 } 
@section head {
    @Html.Partial("_Head")
     <script type="text/javascript">
         function onNodeDrop(e) {
             var dropContainer = $(e.dropTarget).closest('.drop-container');
             var treeview = $('#FileBrowser').data('tTreeView');
             var nodeText = treeview.getItemText(e.item);
             if (dropContainer.length > 0 && dropContainer[0].innerHTML.indexOf(nodeText) == -1) {
                 $('<div><strong>' + nodeText + '</strong></div>')
                            .hide().appendTo(dropContainer).slideDown('fast');

                 e.preventDefault();
             }
         }
         function onNodeSelect(e) {
             var dropContainer = $(e.dropTarget).closest('.drop-container');
             var treeview = $('#FileBrowser').data('tTreeView');
             var nodeText = treeview.getItemValue(e.item);
             $('#selectedPath').val(nodeText);
         }
     </script>
    <style type="text/css">
        #FileBrowser, .drop-container
        {
            border-width: 1px;
            border-style: solid;
            width: 24em; 
        }
        
        #FileBrowser
        {
            height: 24em;
            padding: .5em;
        }
        
        .drop-container
        {
            height: 8em;
            overflow: auto;
            margin-bottom: 1em;
            padding: .70em;
        }
        .pane
        {
            float: left;
            margin: -2em 6em 2em 0;
        }
    </style>
} 